%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plot actual and cftl UR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%load nber dates
load nber

figure,
title('Demographic-adjusted UR')
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(100*hpfilter(Ur_agg{1},.5),'LineWidth',1.3,'Color','k');
hold on, plot(100*hpfilter(Ur_agg{2},.5),'LineWidth',2.5,'Color',[1 0 0],'LineStyle','-');
hold on, plot(100*hpfilter(Ur_agg_LFSS,.5),'LineWidth',2,'Color',[0 .5 0],'LineStyle','--');
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
ylabel('ppt')
ylim(h2,[4 11])
% text(-30,2,name{j}), ylim([-2 2])
set(gca','Xticklabel',num2str((1980:10:2015)'))
set(gca,'Xtick',4*12+1:12*10:length(nber)), xlim([1 length(nber)]),
set(h2,'XLim',get(h1,'XLim'),'Layer','top')
legend('UR','DFM-adjusted UR','Fontsize',8,'Location','North')
legend('UR','DFM-adjusted UR','LFSS-adjusted UR','Fontsize',8,'Location','North')
legend1 = legend(gca,'show');
set(legend1,'Location','North','YColor',[1 1 1],'XColor',[1 1 1],...
    'Color',[1 1 1]);

%difference betw DFM measure and LFSS measure;
dd=100*(Ur_agg{2}-Ur_agg_LFSS);

figure,
bar(1:length(nber),-1+max(0,5*nber),1,'EdgeColor',[.7,.7,.7],'FaceColor',[.7,.7,.7],'LineStyle','none','Clipping','on'),xlim([1 length(nber)])
h1=gca;
set(h1,'YAxisLocation','right','Color','white','XTickLabel',[]);
set(h1,'Fontsize',8)
h2=axes('Position',get(h1,'Position'));
set(h2,'Fontsize',8)
plot(hpfilter(100*(demog_pop),10^5),'LineWidth',1.3,'Color','b','LineStyle','-');
hold on, plot(hpfilter(100*(Ur_agg{1}-Ur_agg{2}),5*10^6),'Color','r','LineWidth',2.5);
hold on,hold on, plot(hpfilter(100*(Ur_agg{1}-Ur_agg_LFSS),5*10^6),'LineWidth',2,'Color',[0 .5 0],'LineStyle','--');
hold on, plot(0*Ur_agg{1},':black','LineWidth',.5)
set(h2,'YAxisLocation','left','Color','none')
ylim(h1,[2 3]), set(h1,'Yticklabel',[]), set(h1,'YTick',[],'XTick',[])
ylabel('ppt of UR')
set(gca','Xticklabel',num2str((1980:10:2015)'))
set(gca,'Xtick',4*12+1:12*10:length(nber)), xlim([1 length(nber)]),
set(h2,'XLim',get(h1,'XLim'),'Layer','top')
legend('Population aging','Demographics from DFM','Demographics from LFSS','Location','NorthEast')
legend1 = legend(gca,'show');
set(legend1,'Location','North','YColor',[1 1 1],'XColor',[1 1 1],...
    'Color',[1 1 1]);
ylim([-1 1.5])

%Data for online Appendix
UR_BLS=100*hpfilter(Ur_agg{1},.5);
UR_DFM=100*hpfilter(Ur_agg{2},.5);
UR_LFSS=100*hpfilter(Ur_agg_LFSS,.5);

trend_aging=hpfilter(100*(demog_pop),10^5);
trend_DFM=hpfilter(100*(Ur_agg{1}-Ur_agg{2}),5*10^6);
trend_LFSS=hpfilter(100*(Ur_agg{1}-Ur_agg_LFSS),5*10^6);

%data for fig 4 (Q freq)
mq([UR_BLS UR_DFM UR_LFSS]);

%data for fig 5 (Y freq)
qy(mq([trend_aging trend_DFM trend_LFSS]));


